package pers.linkong.asr.util;

import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;


    /**
    * @ClassName: TimeKit
    * @Description: TODO(时间处理工具包)
    * @author 独木林空
    * @date 2018年8月7日
    *
    */
    
public class TimeKit {
	
	public static int getWeekDay(){// 获取今天的星期数
		Calendar now = Calendar.getInstance();  
		boolean isFirstSunday = (now.getFirstDayOfWeek() == Calendar.SUNDAY);  
		int weekDay = now.get(Calendar.DAY_OF_WEEK);   
		if(isFirstSunday){  
		    weekDay = weekDay - 1;  
		    if(weekDay == 0){  
		        weekDay = 7;  
		    }
		}
		return weekDay;  
	}
	
	public static Timestamp getNowDate(){
		Date date = new Date();
        String nowTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
        return Timestamp.valueOf(nowTime);
	}
	
	public static Timestamp YMDFormatTS(String date) throws ParseException{
        return new Timestamp(new SimpleDateFormat("yyyy-MM-dd").parse(date).getTime());
	}
	
	public static String TSFormatMD(java.sql.Timestamp timestamp){
		DateFormat sdf = new SimpleDateFormat("MM-dd");
		return sdf.format(timestamp);
	}
	
	public static String TSFormatYMD(java.sql.Timestamp timestamp){
		DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		return sdf.format(timestamp);
	}
	
	public static String TSFormatYMDHMS(java.sql.Timestamp timestamp){
		DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return sdf.format(timestamp);
	}
}
